<template>
    <el-container>
        <el-main>
            <el-table :data="tableData" stripe element-loading-text="拼命加载中" element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.8)" v-loading.fullscreen.lock="loading">
                <el-table-column prop="doctorMu" label="医生MU" width="188" />
                <el-table-column prop="ysName" label="医生姓名" width="188" />
                <el-table-column prop="zsName" label="门诊名称" min-width="108" />
                <el-table-column prop="status" label="报备状态" width="188">
                    <template #="{ status }">
                        <el-tag v-if="status == 0">none</el-tag>
                        <el-tag v-if="status == 1">已报备</el-tag>
                        <el-tag v-if="status == 2">暂不报备</el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="操作" width="568">
                    <template #="{ mu }">
                        <PlainButton :click="() => report(mu, 1)" text="立即报备" />
                        <PlainButton :click="() => report(mu, 2)" text="暂不报备" />
                    </template>
                </el-table-column>
            </el-table>
            <SearchPagination :currentPage="currentPage" :total="total" :limit="limit" @handleCurrentChange="handleCurrentChange" @handleSizeChange="handleSizeChange" />
            <SearchInput placeholder="请输入医生姓名" :change="doChange" />
            <SearchButton :click="searchDoctor" />
            <el-table :data="doctors" stripe>
                <el-table-column prop="mu" label="医生MU" width="188" />
                <el-table-column prop="ysName" label="医生姓名" width="188" />
                <el-table-column prop="zsName" label="门诊名称" min-width="108" />
                <el-table-column label="操作" width="568">
                    <template #="{ mu, ysName, zsName }">
                        <el-button plain @click="initAndReport(mu, ysName, zsName, 1)">
                            立即报备
                        </el-button>
                        <el-button plain @click="initAndReport(mu, ysName, zsName, 2)">
                            暂不报备
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
        </el-main>
    </el-container>
</template>

<script>
import { submit, add, list } from '@/chaos/functions/common/Data';
import Show from '@/chaos/functions/common/Show';

export default {
    name: 'report',
    data() {
        return {
            domain: 'iyaReport',
            doctors: [],
            ysName: ''
        };
    },
    created() {
        this.data.userMu = this.$route.params.mu;
        this.search();
    },
    methods: {
        report(mu, status) {
            submit(
                this.domain + '/update',
                {
                    mu,
                    data: { status }
                },
                () => {
                    this.search();
                    this.doctors = [];
                }
            );
        },
        async initAndReport(doctorMu, ysName, zsName, status) {
            await add('iyaReport', {
                doctorMu,
                ysName,
                zsName,
                status,
                userMu: this.data.userMu
            });
            await this.search();
            this.doctors = [];
        },
        async searchDoctor() {
            const ysName = this.ysName;
            if (ysName == '') {
                Show.info('请输入医生姓名');
                return;
            }
            this.doctors = await list('iyaDoctorZs', { ysName });
        },
        doChange(value) {
            this.doctors = [];
            this.ysName = value;
            this.searchDoctor();
        }
    }
};
</script>
<style lang="less" scoped></style>
